#ifndef SERVER_H
#define SERVER_H


#include <QObject>
#include <QTcpServer>
#include <QMessageBox>
#include <QHostAddress>
#include <QDebug>
#include "message_type.h"
#include <QTcpSocket>
#include <QByteArray>
#include <QJsonDocument>
#include <QJsonParseError>
#include <QJsonObject>
#include <QString>
#include <QSqlQuery>
#include <QSqlDatabase>
#include <QSqlError>
#include "protocol.h"
class Server : public QObject
{
    Q_OBJECT
public:
    explicit Server(QObject *parent = nullptr);
    ~Server();
    void init();

private:
    void startserver();
    void handleTOConnect();
    void handleTORead();
    void initSql();


    void handleLogin(QTcpSocket* socket,QJsonObject& doc);
    void handleChat(QTcpSocket* socket,QJsonObject& doc);
    void handleServerBroadcast(QTcpSocket* socket,QJsonObject& doc);
    void handleRegiste(QTcpSocket* socket,QJsonObject& doc);

    void sendjson(QTcpSocket* socket,Protocol::ResponseType type,QJsonObject& data);


signals:
    void logInfoMessage(Log::MessageType typr,const QString& message);

private:
    QTcpServer* tcpserver;//tcp服务器
    QSqlDatabase sqldb;
};

#endif // SERVER_H
